import request from '@/utils/request'
import type { SkuData, AllSkuResponseData, SkuInfoResponseData } from './type'

enum API {
  SAVESKUINFO_URL = '/admin/product/saveSkuInfo',
  GETSKULIST_URL = '/admin/product/findBySpuId/',
  GETALLSKULIST_URL = '/admin/product/list/',
  CANCELSALE_URL = '/admin/product/cancelSale/',
  ONSALE_URL = '/admin/product/onSale/',
  GETSKUINFO_URL = '/admin/product/getSkuInfo/',
  DELETESKU_URL = '/admin/product/deleteSku/'
}
// 添加SKUinfo
export const addSkuInfoService = (skuInfo: SkuData) =>
  request.post<any, any>(API.SAVESKUINFO_URL, skuInfo)

// 获取sku数据列表
export const getSkuListService = (spuId: number) =>
  request.get<any, any>(API.GETSKULIST_URL + spuId)

// 获取全部sku数据列表
export const getAllSkuListService = (
  page: number | string,
  limit: number | string
) =>
  request.get<any, AllSkuResponseData>(
    API.GETALLSKULIST_URL + `${page}/${limit}`
  )

// 上架sku商品
export const onSaleService = (skuId: number) =>
  request.get<any, any>(API.ONSALE_URL + skuId)

// 下架sku商品
export const cancelSaleService = (skuId: number) =>
  request.get<any, any>(API.CANCELSALE_URL + skuId)

// 获取sku详情
export const getSkuInfoService = (skuId: number) =>
  request.get<any, SkuInfoResponseData>(API.GETSKUINFO_URL + skuId)

// 删除sku商品
export const deleteSkuService = (skuId: number) =>
  request.delete<any, any>(API.DELETESKU_URL + skuId)
